package com.feixiu.mapreduce.partionertest;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowReducer extends Reducer<Text, FlowBean,Text, FlowBean> {
    private FlowBean outV=new FlowBean();
    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {
        //同一个手机号的上行量总和
        long totalUp=0;
        //同一个手机号的下行量总和
        long totalDown=0;

        //同一个key 及手机号的 Flowbean就进行循环
        for (FlowBean flowBean:values){
            totalUp+=flowBean.getUpFlow();
            totalDown+=flowBean.getDownFlow();

        }
        //封装  outV
        outV.setUpFlow(totalUp);
        outV.setDownFlow(totalDown);
        outV.setSumFlow();
        //写出
        context.write(key,outV);

    }
}
